1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Data;
5 using
System.Drawing;
6 using
System.Linq;
7 using
System.Text;
8 using
System.Windows.Forms;
9 using
System.Data.SqlClient;
10 using
Excel = Microsoft.Office.Interop.Excel;
11 namespace
WarehouseManagementSystem
12 {
13     
public partial class frmSalesRecord2 : Form
14     {
15    
16     DataTable dTable;
17     SqlConnection con =
null;
18     SqlDataAdapter adp;
19     DataSet ds;
20     SqlCommand cmd =
null;
21     DataTable dt=
new DataTable();
22     ConnectionString cs =
new ConnectionString();
23     
24         
public frmSalesRecord2()
25         {
26             InitializeComponent();
27         }
28
29         
private void frmSalesRecord_Load(object sender, EventArgs e)
30         {
31             FillCombo();
32         }
33
34         
private void Button3_Click(object sender, EventArgs e)
35         {
36             
if (DataGridView1.DataSource == null)
37             {
38                 MessageBox.Show(
"Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
39                 
return;
40             }
41             
int rowsTotal = 0;
42             
int colsTotal = 0;
43             
int I = 0;
44             
int j = 0;
45             
int iC = 0;
46             System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
47             Excel.Application xlApp =
new Excel.Application();
48
49             
try
50             {
51                 Excel.Workbook excelBook = xlApp.Workbooks.Add();
52                 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[
1];
53                 xlApp.Visible =
true;
54
55                 rowsTotal = DataGridView1.RowCount;
56                 colsTotal = DataGridView1.Columns.Count -
1;
57                 
var _with1 = excelWorksheet;
58                 _with1.Cells.Select();
59                 _with1.Cells.Delete();
60                 
for (iC = 0; iC <= colsTotal; iC++)
61                 {
62                     _with1.Cells[
1, iC + 1].Value = DataGridView1.Columns[iC].HeaderText;
63                 }
64                 
for (I = 0; I <= rowsTotal - 1; I++)
65                 {
66                     
for (j = 0; j <= colsTotal; j++)
67                     {
68                         _with1.Cells[I +
2, j + 1].value = DataGridView1.Rows[I].Cells[j].Value;
69                     }
70                 }
71                 _with1.Rows[
"1:1"].Font.FontStyle = "Bold";
72                 _with1.Rows[
"1:1"].Font.Size = 12;
73
74                 _with1.Cells.Columns.AutoFit();
75                 _with1.Cells.Select();
76                 _with1.Cells.EntireColumn.AutoFit();
77                 _with1.Cells[
1, 1].Select();
78             }
79             
catch (Exception ex)
80             {
81                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
82             }
83             
finally
84             {
85                 
//RELEASE ALLOACTED RESOURCES
86                 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
87                 xlApp =
null;
88             }
89         }
90
91         
private void Button4_Click(object sender, EventArgs e)
92         {
93             
if (DataGridView2.DataSource == null)
94             {
95                 MessageBox.Show(
"Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
96                 
return;
97             }
98             
int rowsTotal = 0;
99             
int colsTotal = 0;
100             
int I = 0;
101             
int j = 0;
102             
int iC = 0;
103             System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
104             Excel.Application xlApp =
new Excel.Application();
105
106             
try
107             {
108                 Excel.Workbook excelBook = xlApp.Workbooks.Add();
109                 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[
1];
110                 xlApp.Visible =
true;
111
112                 rowsTotal = DataGridView2.RowCount;
113                 colsTotal = DataGridView2.Columns.Count -
1;
114                 
var _with1 = excelWorksheet;
115                 _with1.Cells.Select();
116                 _with1.Cells.Delete();
117                 
for (iC = 0; iC <= colsTotal; iC++)
118                 {
119                     _with1.Cells[
1, iC + 1].Value = DataGridView2.Columns[iC].HeaderText;
120                 }
121                 
for (I = 0; I <= rowsTotal - 1; I++)
122                 {
123                     
for (j = 0; j <= colsTotal; j++)
124                     {
125                         _with1.Cells[I +
2, j + 1].value = DataGridView2.Rows[I].Cells[j].Value;
126                     }
127                 }
128                 _with1.Rows[
"1:1"].Font.FontStyle = "Bold";
129                 _with1.Rows[
"1:1"].Font.Size = 12;
130
131                 _with1.Cells.Columns.AutoFit();
132                 _with1.Cells.Select();
133                 _with1.Cells.EntireColumn.AutoFit();
134                 _with1.Cells[
1, 1].Select();
135             }
136             
catch (Exception ex)
137             {
138                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
139             }
140             
finally
141             {
142                 
//RELEASE ALLOACTED RESOURCES
143                 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
144                 xlApp =
null;
145             }
146         }
147
148         
private void Button7_Click(object sender, EventArgs e)
149         {
150             
if (DataGridView3.DataSource == null)
151             {
152                 MessageBox.Show(
"Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
153                 
return;
154             }
155             
int rowsTotal = 0;
156             
int colsTotal = 0;
157             
int I = 0;
158             
int j = 0;
159             
int iC = 0;
160             System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
161             Excel.Application xlApp =
new Excel.Application();
162
163             
try
164             {
165                 Excel.Workbook excelBook = xlApp.Workbooks.Add();
166                 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[
1];
167                 xlApp.Visible =
true;
168
169                 rowsTotal = DataGridView3.RowCount;
170                 colsTotal = DataGridView3.Columns.Count -
1;
171                 
var _with1 = excelWorksheet;
172                 _with1.Cells.Select();
173                 _with1.Cells.Delete();
174                 
for (iC = 0; iC <= colsTotal; iC++)
175                 {
176                     _with1.Cells[
1, iC + 1].Value = DataGridView3.Columns[iC].HeaderText;
177                 }
178                 
for (I = 0; I <= rowsTotal - 1; I++)
179                 {
180                     
for (j = 0; j <= colsTotal; j++)
181                     {
182                         _with1.Cells[I +
2, j + 1].value = DataGridView3.Rows[I].Cells[j].Value;
183                     }
184                 }
185                 _with1.Rows[
"1:1"].Font.FontStyle = "Bold";
186                 _with1.Rows[
"1:1"].Font.Size = 12;
187
188                 _with1.Cells.Columns.AutoFit();
189                 _with1.Cells.Select();
190                 _with1.Cells.EntireColumn.AutoFit();
191                 _with1.Cells[
1, 1].Select();
192             }
193             
catch (Exception ex)
194             {
195                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
196             }
197             
finally
198             {
199                 
//RELEASE ALLOACTED RESOURCES
200                 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
201                 xlApp =
null;
202             }
203         }
204
205         
private void Button9_Click(object sender, EventArgs e)
206         {
207         DataGridView3.DataSource =
null;
208         cmbCustomerName.Text =
"";
209         GroupBox4.Visible =
false;
210         }
211
212         
private void Button2_Click(object sender, EventArgs e)
213         {
214         DataGridView1.DataSource =
null;
215         dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
216         dtpInvoiceDateTo.Text = DateTime.Today.ToString();
217         GroupBox3.Visible =
false;
218         }
219
220         
private void Button6_Click(object sender, EventArgs e)
221         {
222         DateTimePicker1.Text = DateTime.Today.ToString();
223         DateTimePicker2.Text = DateTime.Today.ToString();
224         DataGridView2.DataSource =
null;
225         GroupBox10.Visible =
false;
226         }
227         
public void FillCombo()
228         {
229
230             
try
231             {
232                 con =
new SqlConnection(cs.DBConn);
233                 con.Open();
234                 adp =
new SqlDataAdapter();
235                 adp.SelectCommand =
new SqlCommand("SELECT distinct CustomerName FROM Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID",con);
236                 ds =
new DataSet("ds");
237                 adp.Fill(ds);
238                 dTable = ds.Tables[
0];
239                 cmbCustomerName.Items.Clear();
240                 
foreach (DataRow drow in dTable.Rows)
241                 {
242                     cmbCustomerName.Items.Add(drow[
0].ToString());
243
244                 }
245             }
246             
catch (Exception ex)
247             {
248                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
249             }
250
251         }
252
253         
private void Button1_Click(object sender, EventArgs e)
254         {
255             
try
256             {
257             GroupBox3.Visible =
true;
258             con =
new SqlConnection(cs.DBConn);
259             con.Open();
260             cmd =
new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and InvoiceDate between @d1 and @d2 order by InvoiceDate desc", con);
261             cmd.Parameters.Add(
"@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date;
262             cmd.Parameters.Add(
"@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateTo.Value.Date;
263             SqlDataAdapter myDA =
new SqlDataAdapter(cmd);
264             DataSet myDataSet =
new DataSet();
265             myDA.Fill(myDataSet,
"Invoice_Info");
266             myDA.Fill(myDataSet,
"Customer");
267             DataGridView1.DataSource = myDataSet.Tables[
"Customer"].DefaultView;
268             DataGridView1.DataSource = myDataSet.Tables[
"Invoice_Info"].DefaultView;
269             Int64 sum =
0;
270             Int64 sum1 =
0;
271             Int64 sum2 =
0;
272
273             
foreach (DataGridViewRow r in this.DataGridView1.Rows)
274             {
275                 Int64 i = Convert.ToInt64(r.Cells[
9].Value);
276                 Int64 j = Convert.ToInt64(r.Cells[
10].Value);
277                 Int64 k = Convert.ToInt64(r.Cells[
11].Value);
278                 sum = sum + i;
279                 sum1 = sum1 + j;
280                 sum2 = sum2 + k;
281               
282             }
283             TextBox1.Text = sum.ToString();
284             TextBox2.Text = sum1.ToString();
285             TextBox3.Text = sum2.ToString();
286
287             con.Close();
288             }
289         
catch (Exception ex)
290             {
291             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
292             }
293         }
294
295         
private void cmbCustomerName_SelectedIndexChanged(object sender, EventArgs e)
296         {
297               
try
298             {
299             GroupBox4.Visible =
true;
300             cmbCustomerName.Text = cmbCustomerName.Text.Trim();
301             con =
new SqlConnection(cs.DBConn);
302             con.Open();
303             cmd =
new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and Customername='" + cmbCustomerName.Text.Trim() + "' order by CustomerName,InvoiceDate", con);
304             SqlDataAdapter myDA =
new SqlDataAdapter(cmd);
305             DataSet myDataSet =
new DataSet();
306             myDA.Fill(myDataSet,
"Invoice_Info");
307             myDA.Fill(myDataSet,
"Customer");
308             DataGridView3.DataSource = myDataSet.Tables[
"Customer"].DefaultView;
309             DataGridView3.DataSource = myDataSet.Tables[
"Invoice_Info"].DefaultView;
310             Int64 sum =
0;
311             Int64 sum1 =
0;
312             Int64 sum2 =
0;
313
314             
foreach (DataGridViewRow r in this.DataGridView3.Rows)
315             {
316                 Int64 i = Convert.ToInt64(r.Cells[
9].Value);
317                 Int64 j = Convert.ToInt64(r.Cells[
10].Value);
318                 Int64 k = Convert.ToInt64(r.Cells[
11].Value);
319                 sum = sum + i;
320                 sum1 = sum1 + j;
321                 sum2 = sum2 + k;
322             }
323             TextBox6.Text = sum.ToString();
324             TextBox5.Text = sum1.ToString();
325             TextBox4.Text = sum2.ToString();
326
327             con.Close();
328             }
329         
catch (Exception ex)
330             {
331             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
332             }
333         }
334
335         
private void Button5_Click(object sender, EventArgs e)
336         {
337             
try
338             {
339                 GroupBox10.Visible =
true;
340                 con =
new SqlConnection(cs.DBConn);
341                 con.Open();
342                 cmd =
new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and InvoiceDate between @d1 and @d2 and PaymentDue > 0 order by InvoiceDate desc", con);
343                 cmd.Parameters.Add(
"@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker2.Value.Date;
344                 cmd.Parameters.Add(
"@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker1.Value.Date;
345                 SqlDataAdapter myDA =
new SqlDataAdapter(cmd);
346                 DataSet myDataSet =
new DataSet();
347                 myDA.Fill(myDataSet,
"Invoice_Info");
348                 myDA.Fill(myDataSet,
"Customer");
349                 DataGridView2.DataSource = myDataSet.Tables[
"Customer"].DefaultView;
350                 DataGridView2.DataSource = myDataSet.Tables[
"Invoice_Info"].DefaultView;
351                 Int64 sum =
0;
352                 Int64 sum1 =
0;
353                 Int64 sum2 =
0;
354
355                 
foreach (DataGridViewRow r in this.DataGridView2.Rows)
356                 {
357                     Int64 i = Convert.ToInt64(r.Cells[
9].Value);
358                     Int64 j = Convert.ToInt64(r.Cells[
10].Value);
359                     Int64 k = Convert.ToInt64(r.Cells[
11].Value);
360                     sum = sum + i;
361                     sum1 = sum1 + j;
362                     sum2 = sum2 + k;
363                 }
364                 TextBox12.Text = sum.ToString();
365                 TextBox11.Text = sum1.ToString();
366                 TextBox10.Text = sum2.ToString();
367
368                 con.Close();
369             }
370             
catch (Exception ex)
371             {
372                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
373             }
374         }
375
376     
377         
private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
378         {
379             
string strRowNumber = (e.RowIndex + 1).ToString();
380             SizeF size = e.Graphics.MeasureString(strRowNumber,
this.Font);
381             
if (DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
382             {
383                 DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width +
20));
384             }
385             Brush b = SystemBrushes.ControlText;
386             e.Graphics.DrawString(strRowNumber,
this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
387      
388         }
389
390               
private void DataGridView3_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
391         {
392             
string strRowNumber = (e.RowIndex + 1).ToString();
393             SizeF size = e.Graphics.MeasureString(strRowNumber,
this.Font);
394             
if (DataGridView3.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
395             {
396                 DataGridView3.RowHeadersWidth = Convert.ToInt32((size.Width +
20));
397             }
398             Brush b = SystemBrushes.ControlText;
399             e.Graphics.DrawString(strRowNumber,
this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
400      
401         }
402
403         
private void DataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
404         {
405             
string strRowNumber = (e.RowIndex + 1).ToString();
406             SizeF size = e.Graphics.MeasureString(strRowNumber,
this.Font);
407             
if (DataGridView2.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
408             {
409                 DataGridView2.RowHeadersWidth = Convert.ToInt32((size.Width +
20));
410             }
411             Brush b = SystemBrushes.ControlText;
412             e.Graphics.DrawString(strRowNumber,
this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
413      
414         }
415
416      
417         
private void TabControl1_Click(object sender, EventArgs e)
418         {
419             DataGridView1.DataSource =
null;
420             dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
421             dtpInvoiceDateTo.Text = DateTime.Today.ToString();
422             GroupBox3.Visible =
false;
423             DataGridView3.DataSource =
null;
424             cmbCustomerName.Text =
"";
425             GroupBox4.Visible =
false;
426             DateTimePicker1.Text = DateTime.Today.ToString();
427             DateTimePicker2.Text = DateTime.Today.ToString();
428             DataGridView2.DataSource =
null;
429             GroupBox10.Visible =
false;
430
431         }
432
433         
private void button10_Click(object sender, EventArgs e)
434         {
435             
try
436             {
437                 
if (cmbCustomerName.Text == "")
438                 {
439                     MessageBox.Show(
"Please select customer name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
440                     cmbCustomerName.Focus();
441                     
return;
442                 }
443                 Cursor = Cursors.WaitCursor;
444                 timer1.Enabled =
true;
445                 rptSales rpt =
new rptSales();
446                 
//The report you created.
447                 cmd =
new SqlCommand();
448                 SqlDataAdapter myDA =
new SqlDataAdapter();
449                 POS_DBDataSet myDS =
new POS_DBDataSet();
450                 
//The DataSet you created.
451                 con =
new SqlConnection(cs.DBConn);
452                 cmd.Connection = con;
453                 cmd.CommandText =
"SELECT * from Customer,Invoice_Info where Customer.CustomerID=Invoice_Info.CustomerID and CustomerName='" + cmbCustomerName.Text + "' order by InvoiceDate desc";
454                 cmd.CommandType = CommandType.Text;
455                 myDA.SelectCommand = cmd;
456                 myDA.Fill(myDS,
"Invoice_Info");
457                 myDA.Fill(myDS,
"Customer");
458                 rpt.SetDataSource(myDS);
459                 frmSalesReport frm =
new frmSalesReport();
460                 frm.crystalReportViewer1.ReportSource = rpt;
461                 frm.Visible =
true;
462             }
463             
catch (Exception ex)
464             {
465                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
466             }
467         }
468
469         
private void timer1_Tick(object sender, EventArgs e)
470         {
471             Cursor = Cursors.Default;
472             timer1.Enabled =
false;
473         }
474
475         
private void button8_Click(object sender, EventArgs e)
476         {
477             
try
478             {
479               
480                 Cursor = Cursors.WaitCursor;
481                 timer1.Enabled =
true;
482                 rptSales rpt =
new rptSales();
483                 
//The report you created.
484                 cmd =
new SqlCommand();
485                 SqlDataAdapter myDA =
new SqlDataAdapter();
486                 POS_DBDataSet myDS =
new POS_DBDataSet();
487                 
//The DataSet you created.
488                 con =
new SqlConnection(cs.DBConn);
489                 cmd.Connection = con;
490                 cmd.CommandText =
"SELECT * from Customer,Invoice_Info where Customer.CustomerID=Invoice_Info.CustomerID and InvoiceDate Between @d1 and @d2 order by InvoiceDate desc";
491                 cmd.Parameters.Add(
"@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date;
492                 cmd.Parameters.Add(
"@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateTo.Value.Date;
493                 cmd.CommandType = CommandType.Text;
494                 myDA.SelectCommand = cmd;
495                 myDA.Fill(myDS,
"Invoice_Info");
496                 myDA.Fill(myDS,
"Customer");
497                 rpt.SetDataSource(myDS);
498                 frmSalesReport frm =
new frmSalesReport();
499                 frm.crystalReportViewer1.ReportSource = rpt;
500                 frm.Visible =
true;
501             }
502             
catch (Exception ex)
503             {
504                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
505             }
506         }
507
508         
private void button11_Click(object sender, EventArgs e)
509         {
510             
try{
511              Cursor = Cursors.WaitCursor;
512                 timer1.Enabled =
true;
513                 rptSales rpt =
new rptSales();
514                 
//The report you created.
515                 cmd =
new SqlCommand();
516                 SqlDataAdapter myDA =
new SqlDataAdapter();
517                 POS_DBDataSet myDS =
new POS_DBDataSet();
518                 
//The DataSet you created.
519                 con =
new SqlConnection(cs.DBConn);
520                 cmd.Connection = con;
521                 cmd.CommandText =
"SELECT * from Customer,Invoice_Info where Customer.CustomerID=Invoice_Info.CustomerID and InvoiceDate Between @d1 and @d2 and PaymentDue > 0 order by InvoiceDate desc";
522                 cmd.Parameters.Add(
"@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker2.Value.Date;
523                 cmd.Parameters.Add(
"@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker1.Value.Date;
524                 cmd.CommandType = CommandType.Text;
525                 myDA.SelectCommand = cmd;
526                 myDA.Fill(myDS,
"Invoice_Info");
527                 myDA.Fill(myDS,
"Customer");
528                 rpt.SetDataSource(myDS);
529                 frmSalesReport frm =
new frmSalesReport();
530                 frm.crystalReportViewer1.ReportSource = rpt;
531                 frm.Visible =
true;
532             }
533             
catch (Exception ex)
534             {
535                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
536             }
537         }
538
539         
private void cmbCustomerName_Format(object sender, ListControlConvertEventArgs e)
540         {
541             
if (object.ReferenceEquals(e.DesiredType, typeof(string)))
542             {
543                 e.Value = e.Value.ToString().Trim();
544             }
545         }
546     }
547
548 }


Gõ tìm kiếm nhanh...